package com.flyqiu.flow.core.handler;

import com.flyqiu.flow.core.tools.ProcSequenceCompute;
import com.flyqiu.flow.api.context.ProcInstContext;
import com.flyqiu.flow.api.element.FlyQiuFlowElementManage;
import com.flyqiu.flow.bpmn.element.InclusiveGateway;
import com.flyqiu.flow.bpmn.element.SequenceFlow;
import com.flyqiu.flow.model.entity.ru.ProcRuActivity;

import java.util.List;

/**
 * 包容网关
 */
public class InclusiveGatewayHandler extends BaseComplexGatewayHandler<InclusiveGateway> {
    
    @Override
    protected void startNextActivity(ProcInstContext procContext, ProcRuActivity currentRuActivity) {
        ProcSequenceCompute nextProcSequenceCompute = ProcSequenceCompute.compute(scriptManage, currentElement, procContext.getProcVariables());
        List<SequenceFlow> sequenceFlows = nextProcSequenceCompute.getFinalMultiple(true);
        if (sequenceFlows.isEmpty()) {
            throw new RuntimeException("not find next SequenceFlow");
        }
        FlyQiuFlowElementManage procElementConfig = procContext.getGlobalContext().getFlowElementManage();
        for (SequenceFlow flow : sequenceFlows) {
            procElementConfig.createStartInst(flow.getElementType()).start(procContext, flow.getDefKey());
        }
    }

}
